package com.lvhx.springboot.springbatch.batch;

import org.springframework.batch.core.*;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.batch.core.repository.JobExecutionAlreadyRunningException;
import org.springframework.batch.core.repository.JobInstanceAlreadyCompleteException;
import org.springframework.batch.core.repository.JobRestartException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @auther 吕宏旭
 * @date 2019/9/4 14:21
 */
public class JobLaunch {

    public static void main(String[] args) {
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath:start-config.xml");
        JobLauncher jobLauncher = (JobLauncher) applicationContext.getBean("jobLauncher");
        Job job = (Job) applicationContext.getBean("testPartitionJob");
//        Job job = (Job) applicationContext.getBean("readFlatFileJob");
        try {

//            JobParametersBuilder jobParametersBuilder = new JobParametersBuilder();
//
//            JobParameters jobParameters = jobParametersBuilder.addString("useranme","linux")
//                    .addString("password","123456").toJobParameters();
//
//
//            JobExecution result = jobLauncher.run(job,jobParameters);
            JobExecution result = jobLauncher.run(job,new JobParameters());

            System.out.println(result.toString());
        } catch (JobExecutionAlreadyRunningException e) {
            e.printStackTrace();
        } catch (JobRestartException e) {
            e.printStackTrace();
        } catch (JobInstanceAlreadyCompleteException e) {
            e.printStackTrace();
        } catch (JobParametersInvalidException e) {
            e.printStackTrace();
        }
    }


}
